package org.middleware.common;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Value("${file.upload.path}")
    private String uploadPath;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 确保路径以斜杠结尾
        if (!uploadPath.endsWith("/")) {
            uploadPath += "/";
        }
        // 映射本地文件系统路径到URL路径
        registry.addResourceHandler("/uploads/avatars/**").addResourceLocations("file:" + uploadPath);
    }
}